#include "StdAfx.h"
#include "FileDownloader.h"


CFileDownloader::CFileDownloader(void)
{
	m_pDownloader = new CDownload();
	m_pDownloader->setEventHandler(static_cast<IDownloadEvent*>(this));
}


CFileDownloader::~CFileDownloader(void)
{
}

bool CFileDownloader::DownloadExtraData(std::string sUrl, std::string sDestFile)
{
	USES_CONVERSION;
	if (sUrl.length() < 5)
	{
		return false;
	}
	if (sUrl.substr(4, 3) == "://")
	{
		sUrl = sUrl.substr(7, sUrl.length() - 7);;
	}
	int nPlace = sUrl.find('/');
	if (string::npos == nPlace)
	{
		return false;
	}
	string sHost = sUrl.substr(0, nPlace);
	string sFile = sUrl.substr(nPlace, sUrl.length() - nPlace);
	nPlace = sFile.find_last_of('/');
	if (string::npos == nPlace)
	{
		return false;
	}
	++nPlace;
	string sfileName = sFile.substr(nPlace, sFile.length() - nPlace);
	
	if (sDestFile.empty())
	{
		sDestFile = sfileName;
	}

	return m_pDownloader->DownloadHTTP(sHost.c_str(),sFile,sDestFile,true, false);
}

void CFileDownloader::OnDownloadFailed(DWORD error)
{

}
void CFileDownloader::OnDownloadSuccessed(int nOK)
{


}